<?php

include("config.php");
//获取登录页
$snoopy = new Snoopy;
//模拟HEADER
$snoopy->agent = $agent;
$snoopy->host = IP;
//获取分析表单
$snoopy->fetchform($loginurl);
$res = $snoopy->results;

//超时返回
if ($snoopy->status != '200' || $snoopy->timed_out) {
	echo json_res(true,"systemTimeOut","登录页获取超时！");
	return;
}

//首次设置COOKIE
$snoopy->setcookies();

$_SESSION["__VIEWSTATE"]          = substr($res[1], 64,132);
$_SESSION["__VIEWSTATEGENERATOR"] = substr($res[2], 82,8);
$_SESSION["ASP_NET_SessionId"]    = $snoopy->cookies['ASP.NET_SessionId'];
//var_dump($_SESSION);
//获取验证码
$snoopy2 = new Snoopy;

//模拟HEADER
$snoopy->agent = $agent;
$snoopy2->host = IP;
$snoopy2->referer = $loginurl;
$snoopy2->cookies['ASP.NET_SessionId'] = $_SESSION["ASP_NET_SessionId"];

//获取存储验证图片
$snoopy2->fetch($picurl);
$res2 = $snoopy2->results;

//超时返回
if ($snoopy2->status != '200' || $snoopy2->timed_out) {
	echo json_res(true,"systemTimeOut","验证码获取超时！");
	return;
}

$pic_data = "data:image/gif;base64,".base64_encode($res2);

$session_id = session_id();
	if(empty($_GET['noapi'])){
		$data = array(
		'username'=>'',
		'password'=>'',
		'code'    =>'',
		'code_row'=>$pic_data,
		'token'   =>$session_id
	);
	echo json_res(false,$data);
	return;
}

?>

<!DOCTYPE html>
<html>
<head>
	<title>KillNR</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>

<form action="login" method="POST" name="form" target="_blank">
	学号：<input type="text" name="username" value="S15081200034">
	密码：<input type="password" name="password" value="shanlong11608">
	查询类型：
	<select id="get_type" onchange="document.form.action=this.value;">
		<option value="login">验证密码</option>
	</select>
	验证码：<input type="text" name="code">
	<img src="<?php echo $pic_data; ?>" />
	<input type="hidden" name="noapi" value="1">
	<input type="hidden" name="token" value="<?php echo $session_id;?>">
	<input type="submit" name="submit" value="提交">
</form>
</body>
</html>
